//
//  CNBBSCreatePostViewModel.m
//  CsdnPlus
//
//  Created by 孟瑞瑞 on 2018/7/20.
//  Copyright © 2018年 CSDN. All rights reserved.
//

#import "CNBBSCreatePostViewModel.h"

@implementation CNBBSCreatePostViewModel

/**
 回复论坛
 
 @param topicId 论坛id
 
 @param body 内容
 
 @return 网络请求任务
 */
-(void)getBBSCreatePostWithTopicId:(NSString *)topicId Body:(NSString *)body CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSCreatePostWithTopicId:topicId Body:body completionHandle:^(CNBBSCreatePostModel *model, NSError *error) {
     
        if (!error) {
            self.code = model.code;
            if (self.code == 200) {
                
                self.nickname = model.data.nickname;
                
                self.digg = model.data.digg;
                
                self.is_digged = model.data.is_digged;
                
                self.body = model.data.body;
                
                self.avatar = [model.data.avatar stringByReplacingOccurrencesOfString:@"http:" withString:@"https:"];
                
                self.created_at = model.data.created_at;
                
                self.username = model.data.username;
                
                self.postId = model.data.post_id;
                
                self.floor = model.data.floor;
                
                self.message = model.data.msg;
                
                self.errorStr = model.data.error;
            }
            
        }
        completionHandle(error);
    }];
}


/**
 论坛引用数据
 
 @param postId 回帖id
 
 @return 网络请求任务
 */
-(void)getBBSQuoteWithPostId:(NSString *)postId CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSQuoteWithPostId:postId completionHandle:^(CNBBSQuoteModel *model, NSError *error) {
   
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
                
                self.body = model.data.content;
            }
            
        }
        completionHandle(error);
    }];
}

/**
 点赞论坛
 
 @param topicId 论坛id
 
 @param postId 回帖id
 
 @return 网络请求任务
 */
-(void)getBBSDiggWithTopicId:(NSString *)topicId PostId:(NSString *)postId IsTopic:(BOOL)isTopic CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSDiggWithTopicId:topicId PostId:postId IsTopic:isTopic completionHandle:^(CNBBSFavoriteModel *model, NSError *error) {
    
        if (!error) {
            self.code = model.code;
            self.message = model.msg;
            if (self.code == 200) {
                
                self.success = model.data;
            }
            
        }
        completionHandle(error);
    }];
}

/**
 论坛举报
 
 @param topicId 论坛id
 
 @param postId 回帖id
 
 @return 网络请求任务
 */
-(void)getBBSReportWithTopicId:(NSString *)topicId PostId:(NSString *)postId IsTopic:(BOOL)isTopic ReasonType:(NSString *)reasonType CompletionHandle:(CompletionHandle)completionHandle
{
    self.dataTask = [CNBBSNetManager getBBSReportWithTopicId:topicId PostId:postId IsTopic:isTopic ReasonType:reasonType completionHandle:^(CNBBSReportModel *model, NSError *error) {
        
        if (!error) {
            self.code = model.code;
            
            if (self.code == 200) {
                
                self.success = model.data.status;
                self.message = model.data.msg;
            }
            
        }
        completionHandle(error);
    }];
}
@end
